﻿using System;
using System.Windows.Forms;

namespace Useful.GUI
{
    public partial class DataGridViewColumnSelect : Form
    {
        public DataGridViewColumnSelect(DataGridViewColumnCollection columns)
        {
            InitializeComponent();

            foreach (DataGridViewColumn c in columns)
            {
                cblColumns.Items.Add(c.Name, c.Visible);
            }
        }

        public DataGridViewColumnSelect(DataGridViewColumnCollection columns, DataGridViewColumn[] exclude)
        {
            InitializeComponent();

            foreach (DataGridViewColumn c in columns)
            {
                if (Array.IndexOf<DataGridViewColumn>(exclude, c) == -1)
                    cblColumns.Items.Add(c.Name, c.Visible);
            }
        }

        public bool IsVisible(string name)
        {
            return cblColumns.CheckedItems.Contains(name);
        }

        private bool selected = false;
        private void bSelectAll_Click(object sender, EventArgs e)
        {
            selected = !selected;

            bSelectAll.Text = selected ? "Снять выделение" : "Выделить все";

            for (int i = 0; i < cblColumns.Items.Count; i++)
                cblColumns.SetItemChecked(i, selected);
        }

        private void TerminalViewColumnSelect_Load(object sender, EventArgs e)
        {
            selected = cblColumns.CheckedItems.Count == cblColumns.Items.Count;

            bSelectAll.Text = selected ? "Снять выделение" : "Выделить все";
        }
    }
}
